﻿Imports System.IO
Imports System.Xml
Imports System.Net.Sockets
Imports System.Threading
Imports System.Text
Imports System.Net
Imports System.ComponentModel
Imports System.Configuration
Imports System.Data

Public Class frmMain
    Private ReadOnly key() As Byte = _
{1, 2, 3, 56, 5, 6, 36, 8, 9, 10, 11, 12, 63, 14, _
15, 49, 44, 65, 19, 84, 21, 22, 28, 24}
    Private ReadOnly iv() As Byte = {1, 2, 45, 3, 22, 7, 84, 1}

    ' instantiate the class with the arrays
    Private des As New TripleDES(key, iv)

    Public UserLevel As Integer
    Public UserName As String
    Public Password As String 'encrypted already

    Dim Version As String = "1.3.5.1"

    Public oWS As New aWS.ArmaWebService
    Public Server As Integer = 1
    Dim SettingsFile As String = "ServerSettings.xml"

    Public dtServerList As New DataSet
    Public ds As New DataSet

    Public FileLocation As String = "servers.xml"

    'whether it is currently connected to a server
    Public boolConnected As Boolean = False
    Dim strike As Integer = 0

    Dim dtMissionsList As New DataTable


    Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
        Dim f As New frmEditServers
        f.ShowDialog()
    End Sub

    Private Sub ServerStatus()
        Try
            If oWS.ServerStatus(des.Encrypt(UserName), Password) = True Then
                Me.txbStatus.BackColor = Color.Green
                Me.txbStatus.ForeColor = Color.White
                Me.txbStatus.Text = "RUNNING"
                Me.btnStartServer.Enabled = False
                Me.btnStopServer.Enabled = True
            Else
                Me.txbStatus.BackColor = Color.Red
                Me.txbStatus.ForeColor = Color.White
                Me.txbStatus.Text = "NOT RUNNING"
                Me.btnStartServer.Enabled = True
                Me.btnStopServer.Enabled = False
            End If
            boolConnected = True
        Catch ex As Exception
            Me.txbStatus.BackColor = Color.Red
            Me.btnStartServer.Enabled = True
            Me.btnStopServer.Enabled = False
            boolConnected = False
        End Try

    End Sub

    Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
        ServerStatus()
    End Sub

    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        oWS.Url = "http://24.96.101.10:85/armawebservice/service1.asmx"
        UserName = "captain"
        Password = des.Encrypt("password")
    End Sub

    Private Sub btnStartServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartServer.Click
        Dim StartServer As String = oWS.StartServer(des.Encrypt(UserName), Password)
        If StartServer <> "Success" Then
            MsgBox("Error During Startup" & vbNewLine & StartServer)
        End If
    End Sub

    Private Sub btnStopServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopServer.Click
        oWS.StopServer(des.Encrypt(UserName), Password)
    End Sub
End Class
